import { Vec3 } from 'cc';
import { BehaviorNode, BehaviorStatus } from '../BehaviorNode';
import { AIController } from '../../AIController';

/**
 * 移动行为节点
 * 
 * 功能：
 * 1. 控制AI向目标位置移动
 * 2. 处理到达判定
 * 3. 提供移动状态反馈
 * 
 * 特点：
 * 1. 可配置的到达距离
 * 2. 平滑的移动过程
 * 3. 支持路径跟随
 */
export class MoveToAction extends BehaviorNode {
    private controller: AIController;
    private targetPosition: Vec3;
    private arrivalDistance: number;

    constructor(controller: AIController, targetPosition: Vec3, arrivalDistance: number = 0.5) {
        super();
        this.controller = controller;
        this.targetPosition = targetPosition;
        this.arrivalDistance = arrivalDistance;
    }

    public tick(): BehaviorStatus {
        const currentPos = this.controller.getPosition();
        const distance = Vec3.distance(currentPos, this.targetPosition);

        if (distance <= this.arrivalDistance) {
            this.controller.stopMoving();
            return BehaviorStatus.SUCCESS;
        }

        this.controller.moveTowards(this.targetPosition);
        return BehaviorStatus.RUNNING;
    }
} 